<?php
declare (strict_types = 1);

namespace app\middleware\base_supplier;

use app\model\BaseSupplier;
use think\Exception;

class ActiveSupplierMiddleware
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     */
    public function handle($request, \Closure $next)
    {

        if (input('serv_type') != BaseSupplier::ACTIVE_SERV_TYPE_PRODUCT_GATHER){
            return $next($request);
        }

        $code = input('code');

        if (empty(BaseSupplier::CODE_PRODUCT[$code])) return fail('当前仅支持添加一个活动供应商');


        $request->serv_type = BaseSupplier::CODE_PRODUCT[$code];

        return $next($request);
    }
}
